package cn.abcsys.cloud.devops.web.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.abcsys.cloud.devops.web.dao.ProjectMapper;
import cn.abcsys.cloud.devops.web.entity.GridBean;
import cn.abcsys.cloud.devops.web.entity.PagerModel;
import cn.abcsys.cloud.devops.web.entity.Project;
import cn.abcsys.cloud.devops.web.service.ProjectService;
@Service
public class ProjectServiceImp implements ProjectService{

	@Resource
	private ProjectMapper projectMapper;
	@Override
	public  GridBean  getProjectByEnv(Map<String, Object> map,PagerModel pageModel) {
		// TODO Auto-generated method stub
		int page = pageModel.getPage();
		int rows = pageModel.getRows();
		int totalpage = 0;
		Long totalNum = 0l;
		Page<Project> pageObject = new Page<Project>();
		PageHelper.startPage(page, rows);
		List<Project> projectList= projectMapper.getProjectByEnv(map);
		for(Project project: projectList){
			pageObject.add(project);
		}
		totalpage = ((Page<?>) projectList).getPages();
		totalNum = ((Page<?>) projectList).getTotal();
		GridBean gridBean = new GridBean(page, totalpage, totalNum.intValue(), pageObject);
		return gridBean;
	}
}
